--
-- Author: dbliu
-- Date: 2014-02-27 09:39:09
--

local EC = import("..EC")
local ECProp = class("ECProp",EC)


function ECProp:tick( dt )
    

    if self.model_.fsm__:isState("idle") then
        self:moveRandom()
    end

    self:checkLifeCycle()
end


function ECProp:checkLifeCycle()
    local p = self:getSpritePosition()
    if p.y>app.flightDistance+960*1.1 and self.model_.fsm__:canDoEvent("fall")then
        self.model_.fsm__:doEvent("fall")
    end
    if p.y<app.flightDistance then
        self.view_.body_:removeSelf(true)
        self:removeSelf(true)
    end
end

function ECProp:be_kill()
	self.model_.fsm__:doEvent("kill") 
end

function ECProp:getSpritePosition()
    return self.view_.sprite_:getPositionInCCPoint()
end

function ECProp:setSpritePosition( pos )
    if self.view_.body_ then
        self.view_.body_:setPosition(pos.x, pos.y)
    elseif self.view_.sprite_ then
        self.view_.sprite_:setPosition(pos)   
    end
end

function ECProp:moveRandom()
    
    local p = self:getSpritePosition()
    self:setSpritePosition(ccp(p.x,p.y+70))


end


return ECProp